import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15

ApplicationWindow {
    id: root
    width: Screen.width > 1000 ? 1600 : 800
    height: Screen.height > 1000 ? 2560 : 741
    visible: true
    title: "MarqueeLabel"
    
    // 根据屏幕大小计算缩放因子
    readonly property real scaleFactor: width > 1000 ? 2.0 : 1.0
    
    Rectangle {
        anchors.fill: parent
        color: "#f0f0f0"
        
        ColumnLayout {
            anchors.fill: parent
            anchors.margins: 20 * scaleFactor
            spacing: 20 * scaleFactor
            
            // 标题
            Text {
                text: "跑马灯标签"
                font.pixelSize: 24 * scaleFactor
                font.family: "微软雅黑"
                font.bold: true
                color: "#000000"
                Layout.alignment: Qt.AlignHCenter
            }
            
            // 跑马灯容器（模拟原始UI的frame样式）
            Rectangle {
                Layout.fillWidth: true
                Layout.preferredHeight: 60 * scaleFactor
                color: "#1E1E20"
                radius: 30 * scaleFactor
                
                Row {
                    anchors.fill: parent
                    anchors.leftMargin: 20 * scaleFactor
                    anchors.rightMargin: 20 * scaleFactor
                    
                    MarqueeLabel {
                        id: marqueeLabel
                        width: parent.width
                        height: parent.height
                        text: "花开一千年，花落一千年，花叶生生相错，世世永不相见。彼岸花开开彼岸，奈何桥前可奈何"
                        textColor: "#01EEC3"
                        fontSize: 14 * scaleFactor
                        fontFamily: "Microsoft YaHei"
                        scrollSpeed: 1
                        scrollInterval: 10
                    }
                }
            }
            
            // 输入区域
            Rectangle {
                Layout.fillWidth: true
                Layout.preferredHeight: 180 * scaleFactor
                color: "#ffffff"
                radius: 12 * scaleFactor
                
                ColumnLayout {
                    anchors.fill: parent
                    anchors.margins: 20 * scaleFactor
                    spacing: 15 * scaleFactor
                    
                    // 输入提示
                    Text {
                        text: "自定义跑马灯文字："
                        font.pixelSize: 16 * scaleFactor
                        font.family: "微软雅黑"
                        color: "#333333"
                        Layout.fillWidth: true
                        Layout.topMargin: 8 * scaleFactor
                    }
                    
                    // 文本输入框
                    TextField {
                        id: textInput
                        Layout.fillWidth: true
                        Layout.preferredHeight: 45 * scaleFactor
                        placeholderText: "请输入要显示的文字..."
                        font.pixelSize: 14 * scaleFactor
                        font.family: "微软雅黑"
                        selectByMouse: true
                        padding: 10 * scaleFactor
                        
                        background: Rectangle {
                            anchors.fill: parent
                            color: "#f5f5f5"
                            border.color: textInput.activeFocus ? "#01EEC3" : "#dddddd"
                            border.width: 1
                            radius: 6 * scaleFactor
                        }
                        
                        // 回车键确认输入
                        onAccepted: {
                            if (text.trim() !== "") {
                                marqueeLabel.text = text.trim()
                            }
                        }
                    }
                    
                    // 确认按钮
                    Button {
                        Layout.fillWidth: true
                        Layout.preferredHeight: 45 * scaleFactor
                        text: "更新跑马灯文字"
                        font.pixelSize: 14 * scaleFactor
                        font.family: "微软雅黑"
                        Layout.bottomMargin: 5 * scaleFactor
                        
                        background: Rectangle {
                            anchors.fill: parent
                            color: parent.pressed ? "#00D4B8" : "#01EEC3"
                            radius: 6 * scaleFactor
                        }
                        
                        contentItem: Text {
                            text: parent.text
                            font: parent.font
                            color: "#ffffff"
                            horizontalAlignment: Text.AlignHCenter
                            verticalAlignment: Text.AlignVCenter
                        }
                        
                        onClicked: {
                            if (textInput.text.trim() !== "") {
                                marqueeLabel.text = textInput.text.trim()
                            } else {
                                // 如果输入为空，恢复默认文字
                                marqueeLabel.text = "花开一千年，花落一千年，花叶生生相错，世世永不相见。彼岸花开开彼岸，奈何桥前可奈何"
                                textInput.text = ""
                            }
                        }
                    }
                }
            }
            
            // 说明文字
            Text {
                text: "这是一个跑马灯标签组件，文本会从右向左滚动显示"
                font.pixelSize: 14 * scaleFactor
                font.family: "微软雅黑"
                color: "#666666"
                Layout.alignment: Qt.AlignHCenter
            }
        }
    }
}
